import 'package:flutter/material.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:get/get.dart';
import 'package:xinxuan/common/network_image_util.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:xinxuan/controllers/seckill_controller/seckill_detail_page_controller.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class SeckillDetailPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: pageBgColor,
      appBar: AppBarUtil(
        title: '商品详情',
        backgroundColor: pageBgColor,
      ),
      body: GetBuilder<SeckillDetailPageController>(
        init: SeckillDetailPageController(),
        builder: (controller) {
          return ScrollConfigurationCommon(child: ListView(
            children: [
              NetworkImageUtil(
                url: controller.seckillDetailData.value.image ?? '', 
                width: 375.w, 
                height: 375.w
              ),
              Container(
                padding: EdgeInsets.symmetric(horizontal: 16.w),
                color: bgWhiteColor,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    SizedBox(height: 12.h),
                    Text.rich(
                      TextSpan(
                        children: [
                          WidgetSpan(
                            child: Container(
                              padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 1.h),
                              margin: EdgeInsets.only(right: 6.w),
                              decoration: BoxDecoration(
                                color: bgPinkColor,
                                borderRadius: BorderRadius.circular(3.w),
                              ),
                              child: Text(
                                '抢购价',
                                style: TextStyle(
                                  color: mainTextColor,
                                  fontSize: 12.sp
                                ),
                              ),
                            )
                          ),
                          TextSpan(
                            text: '¥',
                            style: TextStyle(
                              color: mainTextColor,
                              fontSize: 14.sp,
                              fontWeight: FontWeight.bold
                            )
                          ),
                          TextSpan(
                            text: '${controller.seckillDetailData.value.price}',
                            style: TextStyle(
                              color: mainTextColor,
                              fontSize: 24.sp,
                              fontWeight: FontWeight.bold
                            )
                          )
                        ]
                      )
                    ),
                    SizedBox(height: 6.h),
                    Text(
                      '${controller.seckillDetailData.value.title}',
                      style: TextStyle(
                        color: textBlackColor,
                        fontSize: 16.sp
                      ),
                    ),
                    SizedBox(height: 12.h),
                  ],
                ),
              ),
              Container(
                margin: EdgeInsets.only(top: 52.h),
                padding: EdgeInsets.symmetric(horizontal: 25.w),
                child: ButtonUtil(
                  text: '生成订单', 
                  fontSize: 14.sp, 
                  borderRadius: 18.w, 
                  height: 36.h, 
                  onTop: () {
                    controller.submitSeckillOrder();
                  }
                ),
              )
            ],
          ));
        },
      ),
    );
  }
}